package com.qinyu.treehole.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qinyu.treehole.entities.Forward;
import com.qinyu.treehole.mapper.ForwardMapper;
import com.qinyu.treehole.service.ForwardService;
import org.springframework.stereotype.Service;

@Service
public class ForwardServiceImpl extends ServiceImpl<ForwardMapper, Forward> implements ForwardService {

    @Override
    public boolean saveForward(Integer userId, Integer feedId) {
        Forward forward = new Forward();
        forward.setUserId(userId);
        forward.setFeedId(feedId);
        return save(forward);
    }

    @Override
    public long getForwardCountByFeedId(Integer feedId) {
        return count(new QueryWrapper<Forward>().eq("feed_id", feedId));
    }

    @Override
    public boolean isForwardFeedByUserId(Integer feedId, Integer userId) {
        return count(new QueryWrapper<Forward>().and(i->i.eq("user_id", userId)).eq("feed_id", feedId)) > 0;
    }
}
